﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Micronet.OpenWeb.Com.BLL;
using Micronet.OpenWeb.Com.Controls;
using Micronet.OpenWeb.Utils;

namespace Micronet.OpenWeb.OpenWeb.Admin.Views.Shared.Forum
{
    public partial class ForumCategoriesAdmin : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void IsEnabledCheckBox_CheckedChanged(object sender, EventArgs e)
        {

            var IsEnabbed = (OwCheckBox)sender;

            var obj = OwBlogCategoriesBLL.OwGetEntity(IsEnabbed.Text.Trim().OwToInt64TryParse());

            obj.IsEnabled = IsEnabbed.Checked.ToString().OwToBoolean();
            obj.EditingUser = (Guid?)Membership.GetUser().ProviderUserKey;
            if (OwBlogCategoriesBLL.OwSave(obj) > 0)
            {
                ForumCategoiesAdmin.Rebind();
                Alert();
            }
        }

        protected void IsHomeDisplayCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var isHomeDisplayCheckBox = (OwCheckBox)sender;
            var obj = OwBlogCategoriesBLL.OwGetEntity(isHomeDisplayCheckBox.Text.Trim().OwToInt64TryParse());
            obj.IsHomePage = isHomeDisplayCheckBox.Checked.ToString().OwToBoolean();
            obj.EditingUser = (Guid?)Membership.GetUser().ProviderUserKey;
            if (OwBlogCategoriesBLL.OwSave(obj) > 0)
            {
                ForumCategoiesAdmin.Rebind();
                Alert();
            }
        }
        protected void Alert()
        {
            OwN.Text = Resources.OpenWeb.ItemSavedMeassage.ToString();
            OwN.Title = Resources.OpenWeb.ItemSavedMeassage.ToString();
            OwN.Show();
        }

        protected void IsMenuCbb_CheckedChanged(object sender, EventArgs e)
        {
            var isMenuCheckBox = (OwCheckBox)sender;
            var obj = OwBlogCategoriesBLL.OwGetEntity(isMenuCheckBox.Text.Trim().OwToInt64TryParse());
            obj.IsMenu = isMenuCheckBox.Checked.ToString().OwToBoolean();

            obj.EditingUser = (Guid?)Membership.GetUser().ProviderUserKey;
            if (OwBlogCategoriesBLL.OwSave(obj) > 0)
            {
                ForumCategoiesAdmin.Rebind();
                Alert();
            }
        }

        protected void IsDeletedCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var isDeletedCheckBox = (OwCheckBox)sender;
            var obj = OwBlogCategoriesBLL.OwGetEntity(isDeletedCheckBox.Text.Trim().OwToInt64TryParse());
            obj.IsDeleted = isDeletedCheckBox.Checked.ToString().OwToBoolean();
            obj.EditingUser = (Guid?)Membership.GetUser().ProviderUserKey;
            if (OwBlogCategoriesBLL.OwSave(obj) > 0)
            {
                ForumCategoiesAdmin.Rebind();
                Alert();
            }
        }
    }
}